package com.cskaoyan.controller.wx;

import com.cskaoyan.bean.BaseRespVo;
import com.cskaoyan.bean.wx.home.vo.*;
import com.cskaoyan.service.CouponService;
import com.cskaoyan.service.GoodsService;
import com.cskaoyan.service.TopicService;
import com.cskaoyan.service.category.CategoryService;
import com.cskaoyan.service.wx.home.WXAdService;
import com.cskaoyan.service.wx.home.WXBrandService;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * 创建日期: 2022/05/08 11:37
 *
 * @author JinLu Zhou
 */
@RestController
@RequestMapping("wx/home")
public class WXHomeController {
    @Autowired
    WXAdService wxAdService;
    @Autowired
    WXBrandService wxBrandService;
    @Autowired
    CategoryService categoryService;
    @Autowired
    CouponService couponService;
    @Autowired
    GoodsService goodsService;
    @Autowired
    TopicService topicService;

    @RequestMapping("index")
    public BaseRespVo index() {


        List<BannerVo> bannerList = wxAdService.queryAllBanner();
        List<BrandVo> brandVoList = wxBrandService.queryAllBrand();
        List<ChannelVo> channelVos = categoryService.selectAllChannel();
        List<CouponVo> couponVoList = couponService.queryAllBrandCoupon();

        //floorGoodsList

        ArrayList<FloorGoods> floorGoods1 = new ArrayList<>();
        for (ChannelVo channelVo : channelVos) {
            FloorGoods floorGoods = new FloorGoods();
            floorGoods.setId(channelVo.getId());
            floorGoods.setName(channelVo.getName());

            List<GoodsVo> goodsVoList = categoryService.queryFloorGoods(channelVo.getId());
            floorGoods.setGoodsList(goodsVoList);
            floorGoods1.add(floorGoods);
        }

        List<GrouponVo> grouponVoList = goodsService.queryAllGroupon();
        List<HotGoodsVo> hotGoodsVoList = goodsService.queryAllHotGoods();
        List<NewGoodsVo> newGoodsVoList = goodsService.queryAllNewGoods();
        List<TopicVo> topicVoList = topicService.queryAllTopic();

        HomeDataVo homeDataVo = new HomeDataVo();
        homeDataVo.setBanner(bannerList);
        homeDataVo.setBrandList(brandVoList);
        homeDataVo.setChannel(channelVos);
        homeDataVo.setCouponList(couponVoList);
        homeDataVo.setFloorGoodsList(floorGoods1);//
        homeDataVo.setGrouponList(grouponVoList);
        homeDataVo.setHotGoodsList(hotGoodsVoList);
        homeDataVo.setNewGoodsList(newGoodsVoList);
        homeDataVo.setTopicList(topicVoList);

        BaseRespVo<HomeDataVo> homeDataVoBaseRespVo = new BaseRespVo<>();
        homeDataVoBaseRespVo.setErrno(0);
        homeDataVoBaseRespVo.setErrmsg("成功");
        homeDataVoBaseRespVo.setData(homeDataVo);
        return homeDataVoBaseRespVo;
    }
}
